package day15.Task;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Student implements Comparable<Student>{
    private String ID;
    private String name;
    private Integer math;
    private Integer physics;

    public Student(String ID, String name, Integer math, Integer physics) {
        this.ID = ID;
        this.name = name;
        this.math = math;
        this.physics = physics;
    }

    public String getID() {
        return ID;
    }

    public void setID(String ID) {
        this.ID = ID;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getMath() {
        return math;
    }

    public void setMath(Integer math) {
        this.math = math;
    }

    public Integer getPhysics() {
        return physics;
    }

    public void setPhysics(Integer physics) {
        this.physics = physics;
    }

    @Override
    public String toString() {
        return ID + " "+ name +" "+(math+physics);
    }

    @Override
    public int compareTo(Student o) {

        return o.getMath()+o.getPhysics()-this.getPhysics()-this.getMath();
    }
}
class Main{
    public static void main(String[] args) {
        List<Student> list=new ArrayList<>();
        Scanner sc=new Scanner(System.in);
        while(true){
            String s = sc.nextLine();
            if(s.equals("end")){
                break;
            }
            String[] s1 = s.split(" ");
            list.add(new Student(s1[0], s1[1], Integer.parseInt(s1[2]), Integer.valueOf(s1[3])));
        }
        Collections.sort(list);
        for (Student student : list) {
            System.out.println(student);
        }
    }
}
